package com.boot.system.config;

import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.same.SaSameUtil;
import cn.dev33.satoken.stp.StpUtil;
import com.boot.system.fegin.SysMenuClient;
import com.boot.system.fegin.SysRoleClient;
import com.boot.system.fegin.SysUserClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

import java.util.function.Consumer;

@Configuration
public class RestClientConfig {
    private final String BASE_URL="http://localhost:9090/boot/system/";

    @Bean
    public SysUserClient sysUserClient() {
        WebClient client = WebClient.builder()

                .baseUrl(BASE_URL)
                .defaultHeader(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken())
                .build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(WebClientAdapter.create(client))
                .build();
        return factory.createClient(SysUserClient.class);
    }
    @Bean
    public SysMenuClient sysMenuClient() {
        WebClient client = WebClient.builder()
                .baseUrl(BASE_URL)
                .defaultHeader(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken())
                .build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(WebClientAdapter.create(client))
                .build();
        return factory.createClient(SysMenuClient.class);
    }

    @Bean
    public SysRoleClient sysRoleClient() {
        WebClient client = WebClient.builder()
                .baseUrl(BASE_URL)
                .defaultHeader(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken())
                .build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(WebClientAdapter.create(client))
                .build();
        return factory.createClient(SysRoleClient.class);
    }
}
